/**
 * test case for api_account_history
 */
describe("api_account_history", function() {
	beforeEach(function() {
		App.initSession();
		App.getSession().setTimeStamp(new Date());
	});

	describe('bsoi accountHistory', function() {
		var account = App.HaveAccount.create();
		var callback = jasmine.createSpy();
		
		beforeEach(function() {
			spyOn(bsoi, "accountHistory").andCallFake(function() {
				t_accountHistoryResponse = {
			        "accountHistoryList": [
			            {
			                "account": {
			                    "dealFlag": "N",
			                    "localCurrentBalance": 7849236.63,
			                    "localAvailableBalance": 7849236.63,
			                    "iban": "",
			                    "productCategory": "CASA",
			                    "productCode": "CASA",
			                    "subProductCode": "518",
			                    "accountNumber": "18000111614",
			                    "accountName": "Saving Account-Pensioners",
			                    "accountDescription": "Saving Account-Pensioners",
			                    "accountStatus": "O",
			                    "currencyCode": "INR",
			                    "currentBalance": 7849236.63,
			                    "availableBalance": 7849236.63,
			                    "onlineFlag": true,
			                    "islamicFlag": false,
			                    "productDescription": "Saving Account-Pensioners"
			                },
			                "transactionList": [
			                    {
			                        "runningBalance": 7849236.63,
			                        "toAccountNumber": "18000111614",
			                        "withdrawalAmount": 100,
			                        "amount": 100,
			                        "transactionDescription": "IBANKING TRF TO EPAYPTCL IBK EPAY-PTCL PK-014-111001-121748468-805955-001",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": 7849336.63,
			                        "toAccountNumber": "18000111614",
			                        "withdrawalAmount": 8371,
			                        "amount": 8371,
			                        "transactionDescription": "IBANKING CREDIT CARD PAYMENT PAYMENT OF 376294620252002",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": 7857707.63,
			                        "toAccountNumber": "18000111614",
			                        "withdrawalAmount": 500,
			                        "amount": 500,
			                        "transactionDescription": "IBANKING TRF TO EPAYWATEEN IBK EPAY-WATEEN PK-014-111001-133335015-476438-027",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": 7858207.63,
			                        "toAccountNumber": "18000111614",
			                        "withdrawalAmount": 250,
			                        "amount": 250,
			                        "transactionDescription": "IBANKING TRF TO EPAYPTCL IBK EPAY-PTCL PK-014-111001-123804684-799404-015",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": 7858457.63,
			                        "toAccountNumber": "18000111614",
			                        "withdrawalAmount": 10.55,
			                        "amount": 10.55,
			                        "transactionDescription": "IBANKING CREDIT CARD PAYMENT PAYMENT OF 376294620252002",
			                        "postDate": "2011-09-30T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": 7858468.18,
			                        "toAccountNumber": "",
			                        "depositAmount": 8000000,
			                        "amount": 8000000,
			                        "transactionDescription": "CASH DEPOSIT-KHI-SHERATON",
			                        "postDate": "2011-09-30T00:00:00.000+0530",
			                        "transactionType": "C",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -141531.82,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 2130,
			                        "amount": 2130,
			                        "transactionDescription": "IBK UBPS 1 LINK PAYMENT OF 10300000002      6272719213456115",
			                        "postDate": "2011-10-02T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -139401.82,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 236.66,
			                        "amount": 236.66,
			                        "transactionDescription": "IBANKING TRF TO 10000111603",
			                        "postDate": "2011-10-03T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -139165.16,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 11.65,
			                        "amount": 11.65,
			                        "transactionDescription": "IBFT TFR-TO 09904415912 6272719213456115",
			                        "postDate": "2011-10-03T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -139153.51,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 1.6,
			                        "amount": 1.6,
			                        "transactionDescription": "IBK UBPS 1 LINK PAYMENT OF 0000002000       6272719213456115",
			                        "postDate": "2011-10-11T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -139151.91,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 1.6,
			                        "amount": 1.6,
			                        "transactionDescription": "IBK UBPS 1 LINK PAYMENT OF 0000002000       6272719213456115",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -139150.31,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 2.2,
			                        "amount": 2.2,
			                        "transactionDescription": "IBK UBPS 1 LINK PAYMENT OF 1700416020049    6272719213456115",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -139148.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 3,
			                        "amount": 3,
			                        "transactionDescription": "IBK UBPS 1 LINK PAYMENT OF 10300075435      6272719213456115",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -139145.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 550,
			                        "amount": 550,
			                        "transactionDescription": "IBK UBPS 1 LINK PAYMENT OF 03335100047      6272719213456115",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -138595.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 5000,
			                        "amount": 5000,
			                        "transactionDescription": "IBANKING TRF TO 18960077001",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -133595.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 5000,
			                        "amount": 5000,
			                        "transactionDescription": "IBANKING TRF TO 18960077001",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -128595.11,
			                        "toAccountNumber": "",
			                        "depositAmount": 20,
			                        "amount": 20,
			                        "transactionDescription": "IBANKING TRF FROM 18000111602",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "C",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -128615.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 250,
			                        "amount": 250,
			                        "transactionDescription": "IBK UBPS 1 LINK PAYMENT OF 03332341710      6272719213456115",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -128365.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 62900,
			                        "amount": 62900,
			                        "transactionDescription": "IBK UBPS 1 LINK PAYMENT OF                  6272719213456115",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -65465.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 900,
			                        "amount": 900,
			                        "transactionDescription": "IBK UBPS 1 LINK PAYMENT OF 03335100047      6272719213456115",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -64565.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 500,
			                        "amount": 500,
			                        "transactionDescription": "IBK UBPS 1 LINK PAYMENT OF 03335100047      6272719213456115",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -64065.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 62900,
			                        "amount": 62900,
			                        "transactionDescription": "IBK UBPS 1 LINK PAYMENT OF                  6272719213456115",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -1165.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 250,
			                        "amount": 250,
			                        "transactionDescription": "IBK UBPS 1 LINK PAYMENT OF 03332341710      6272719213456115",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -915.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 780,
			                        "amount": 780,
			                        "transactionDescription": "IBK UBPS 1 LINK PAYMENT OF 0000130000       6272719213456115",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -135.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 100,
			                        "amount": 100,
			                        "transactionDescription": "IBANKING TRF TO 18000111602",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -35.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 10,
			                        "amount": 10,
			                        "transactionDescription": "IBANKING TRF TO 18960077001",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    },
			                    {
			                        "runningBalance": -25.11,
			                        "toAccountNumber": "",
			                        "withdrawalAmount": 25.11,
			                        "amount": 25.11,
			                        "transactionDescription": "IBANKING TRF TO 18000111602",
			                        "postDate": "2011-10-01T00:00:00.000+0530",
			                        "transactionType": "D",
			                        "transactionCurrency": "INR"
			                    }
			                ]
			            }
			        ],
			        "responseHeader": {
			            "status": 1,
			            "currentTimestamp": "2011-10-01T18:58:31.585+0530",
			            "nonce": "a08b0eff0b7b34a611b2e529c20a7351"
			        }
			    }
				App.api_accountHistory._processAccountHistory(t_accountHistoryResponse);
			});
		});

		it('User can get account history', function() {
			spyOn(App.api_accountHistory, "_processAccountHistory");
			spyOn(account, "getProductVO");

			App.api_accountHistory.getAccountHistory(account, callback);
			
			expect(App.api_accountHistory.callbackAccountHistory).toEqual(callback);
			expect(bsoi.accountHistory).toHaveBeenCalled();
			
			expect(App.api_accountHistory._processAccountHistory).toHaveBeenCalledWith(t_accountHistoryResponse);
		});
		
	});

	describe('bsoi cardHistory', function() {
		var account = App.CardAccount.create();
		var callback = jasmine.createSpy();
		
		beforeEach(function() {
			spyOn(bsoi, "cardHistory").andCallFake(function() {
				cardHistoryResponse = {
			        "cardHistoryList": [
			            {
			                "card": {
			                    "supplementaryCardList": [],
			                    "holderType": "Primary",
			                    "cardHolderName": "KHAWAJA M AJMAL",
			                    "statementBalance": -5430.81,
			                    "unbilledCharges": 2351.72,
			                    "unbilledPayments": -30.81,
			                    "outStandingBalance": -3109.9,
			                    "availableCreditLimit": 453109.9,
			                    "minimumAmountDue": 0,
			                    "cardExpiryDate": "2013-05-01T00:00:00.000+0400",
			                    "paymentDueDate": "2012-01-09T00:00:00.000+0400",
			                    "productCategory": "CARD",
			                    "productCode": "CARD",
			                    "accountNumber": "4075690000638650",
			                    "accountDescription": "Visa Platinum Karachi",
			                    "accountStatus": "ACTIVE",
			                    "currencyCode": "PKR",
			                    "onlineFlag": true,
			                    "islamicFlag": false
			                },
			                "transactionList": [
			                    {
			                        "otherCurrencyAmount": 15.86,
			                        "withdrawalAmount": 15.86,
			                        "accountNumber": "4075690000638650",
			                        "amount": 15.86,
			                        "transactionDescription": "ONLINE CASH ADV",
			                        "postDate": "2011-10-01T00:00:00.000+0400",
			                        "transactionType": "D",
			                        "transactionCurrency": "PKR"
			                    },
			                    {
			                        "otherCurrencyAmount": 15.86,
			                        "withdrawalAmount": 15.86,
			                        "accountNumber": "4075690000638650",
			                        "amount": 15.86,
			                        "transactionDescription": "ONLINE CASH ADV",
			                        "postDate": "2011-10-01T00:00:00.000+0400",
			                        "transactionType": "D",
			                        "transactionCurrency": "PKR"
			                    },
			                    {
			                        "otherCurrencyAmount": 1000,
			                        "withdrawalAmount": 1000,
			                        "accountNumber": "4075690000638650",
			                        "amount": 1000,
			                        "transactionDescription": "CASH ADVANCE FEE",
			                        "postDate": "2011-10-01T00:00:00.000+0400",
			                        "transactionType": "D",
			                        "transactionCurrency": "PKR"
			                    },
			                    {
			                        "otherCurrencyAmount": 1000,
			                        "withdrawalAmount": 1000,
			                        "accountNumber": "4075690000638650",
			                        "amount": 1000,
			                        "transactionDescription": "CASH ADVANCE FEE",
			                        "postDate": "2011-10-01T00:00:00.000+0400",
			                        "transactionType": "D",
			                        "transactionCurrency": "PKR"
			                    },
			                    {
			                        "otherCurrencyAmount": 160,
			                        "withdrawalAmount": 160,
			                        "accountNumber": "4075690000638650",
			                        "amount": 160,
			                        "transactionDescription": "Federal Excise Duty",
			                        "postDate": "2011-10-01T00:00:00.000+0400",
			                        "transactionType": "D",
			                        "transactionCurrency": "PKR"
			                    },
			                    {
			                        "otherCurrencyAmount": 160,
			                        "withdrawalAmount": 160,
			                        "accountNumber": "4075690000638650",
			                        "amount": 160,
			                        "transactionDescription": "Federal Excise Duty",
			                        "postDate": "2011-10-01T00:00:00.000+0400",
			                        "transactionType": "D",
			                        "transactionCurrency": "PKR"
			                    },
			                    {
			                        "otherCurrencyAmount": -30.81,
			                        "depositAmount": 30.81,
			                        "accountNumber": "4075690000638650",
			                        "amount": 30.81,
			                        "transactionDescription": "PAYMENT RECD.-THANK YOU",
			                        "postDate": "2011-10-01T00:00:00.000+0400",
			                        "transactionType": "C",
			                        "transactionCurrency": "PKR"
			                    }
			                ]
			            }
			        ],
			        "responseHeader": {
			            "status": 1,
			            "currentTimestamp": "2011-10-01T20:00:53.000+0400",
			            "nonce": "81834acd4c594443cbd43819b8bc7897"
			        }
			    }
				App.api_accountHistory._processCardHistory(t_accountHistoryResponse);
			});
		});

		it('User can get card history', function() {
			spyOn(account, "getProductVO");
			spyOn(App.api_accountHistory, "_processCardHistory");

			App.api_accountHistory.getAccountHistory(account, callback);
			
			expect(App.api_accountHistory.callbackAccountHistory).toEqual(callback);
			expect(bsoi.cardHistory).toHaveBeenCalled();
			
			expect(App.api_accountHistory._processCardHistory).toHaveBeenCalledWith(t_accountHistoryResponse);
		});
		
	});
	
	describe('bsoi loanHistory', function() {
		var account = App.LoanAccount.create();
		var callback = jasmine.createSpy();
		
		beforeEach(function() {
			spyOn(bsoi, "loanHistory").andCallFake(function() {
				loanHistoryResponse = {
			        "loanHistoryList": [],
			        "responseHeader": {
			            "status": 1,
			            "currentTimestamp": "2011-10-01T20:00:53.000+0400",
			            "nonce": "a2e191986b81103a6bc6f106ba9f5d77"
			        }
			    }
				App.api_accountHistory._processLoanHistory(t_accountHistoryResponse);
			});
		});

		it('User can get loan history', function() {
			spyOn(account, "getProductVO");
			spyOn(App.api_accountHistory, "_processLoanHistory");

			App.api_accountHistory.getAccountHistory(account, callback);
			
			expect(App.api_accountHistory.callbackAccountHistory).toEqual(callback);
			expect(bsoi.loanHistory).toHaveBeenCalled();
			
			expect(App.api_accountHistory._processLoanHistory).toHaveBeenCalledWith(t_accountHistoryResponse);
		});
		
	});
	
	describe('bsoi account history error', function() {
		var accountHistoryError, cardHistoryError, loanHistoryError;
		beforeEach(function() {
			accountHistoryError = {
				    "accountHistoryResponse": {
				        "responseHeader": {
				            "status": 0,
				            "errorCode": "ERR_NO_ACCOUNT_FOUND",
				            "errorMessage": "Sorry, we are unable to process your request at this time. Should you require immediate assistance, please contact Phone Banking or write to us at customer.care@sc.com (Err Code:2000)",
				            "currentTimestamp": "2012-05-30T16:25:26.004+0530",
				            "nonce": "861fbc4426a4faa865913a40e0c49ed7"
				        }
				    }
				};
			cardHistoryError = {
				    "cardHistoryResponse": {
				        "responseHeader": {
				            "status": 0,
				            "errorCode": "ERR_NO_ACCOUNT_FOUND",
				            "errorMessage": "Sorry, we are unable to process your request at this time. Should you require immediate assistance, please contact Phone Banking or write to us at customer.care@sc.com (Err Code:2000)",
				            "currentTimestamp": "2012-05-30T16:12:58.828+0530",
				            "nonce": "cd4df9c99af080eee75f0b5bff78c2f2"
				        }
				    }
				};
			loanHistoryError = {
				    "loanHistoryResponse": {
				        "responseHeader": {
				            "status": 0,
				            "errorCode": "ERR_NO_ACCOUNT_FOUND",
				            "errorMessage": "Sorry, we are unable to process your request at this time. Should you require immediate assistance, please contact Phone Banking or write to us at customer.care@sc.com (Err Code:2000)",
				            "currentTimestamp": "2012-05-30T16:26:50.568+0530",
				            "nonce": "eff971bb0413934ed40b80ade05ec6aa"
				        }
				    }
				};
		});
		
		it('Should get Exception with response error', function() {
			App.api_accountHistory.callbackAccountHistory = function(transactionList, error) {
				expect(error.getErrorCode()).toEqual('ERR_NO_ACCOUNT_FOUND');
			};
			
			App.api_accountHistory._processAccountHistory(accountHistoryError, null);
			App.api_accountHistory._processCardHistory(cardHistoryError, null);
			App.api_accountHistory._processLoanHistory(loanHistoryError, null);
		});
		
	});
});
